#include "SceneTabWidget.h"
#include "GLWidget.h"
#include <QIcon>

SceneTabWidget::SceneTabWidget(QWidget *parent, Qt::WFlags flags)
	: QWidget(parent, flags)
{
	ui.setupUi(this);
	m_iconPlay = true;

	ui.labelVel->setVisible(false);
	ui.labeldx->setVisible(false);
	ui.labeldt->setVisible(false);
	ui.dsbVel->setVisible(false);
	ui.dsbDX->setVisible(false);
	ui.dsbDT->setVisible(false);

	ui.buttonPlay->setIcon(QIcon(QPixmap("icons/play.png")));
	ui.buttonStep->setIcon(QIcon(QPixmap("icons/step.png")));
	ui.buttonRestart->setIcon(QIcon(QPixmap("icons/reset.png")));
}

SceneTabWidget::~SceneTabWidget(void)
{
}

void SceneTabWidget::connectToGLWidget(GLWidget * glw) {

	connect(ui.radioA, SIGNAL(clicked()), glw, SLOT(setTypeA()));	
	connect(ui.radioB, SIGNAL(clicked()), glw, SLOT(setTypeB()));	
	connect(ui.radioC, SIGNAL(clicked()), glw, SLOT(setTypeC()));	
	connect(ui.radioD, SIGNAL(clicked()), glw, SLOT(setTypeD()));	
	connect(ui.radioE, SIGNAL(clicked()), glw, SLOT(setTypeE()));	
	connect(ui.radioF, SIGNAL(clicked()), glw, SLOT(setTypeF()));	
	connect(ui.radioG, SIGNAL(clicked()), glw, SLOT(setTypeG()));	

	connect(ui.checkLeft,  SIGNAL(clicked(bool)), glw, SLOT(setDrawLeft(bool)));
	connect(ui.checkRight, SIGNAL(clicked(bool)), glw, SLOT(setDrawRight(bool)));
	connect(ui.checkBoth,  SIGNAL(clicked(bool)), glw, SLOT(setDrawBoth(bool)));
	connect(ui.checkLine,  SIGNAL(clicked(bool)), glw, SLOT(setDrawZero(bool)));

	connect(ui.buttonPlay,    SIGNAL(clicked()), this, SLOT(changePlayIcon()));
	connect(ui.buttonPlay,    SIGNAL(clicked()), glw,  SLOT(play()));
	connect(ui.buttonStep,    SIGNAL(clicked()), glw,  SLOT(step()));
	connect(ui.buttonRestart, SIGNAL(clicked()), glw,  SLOT(setValorsInicials()));

	connect(ui.spinL,	 SIGNAL(valueChanged(int)),    glw, SLOT(setL(int)));
	connect(ui.spinReps, SIGNAL(valueChanged(int)),    glw, SLOT(setReps(int)));
	connect(ui.dsbVel,   SIGNAL(valueChanged(double)), glw, SLOT(setVel(double)));
	connect(ui.dsbDX,    SIGNAL(valueChanged(double)), glw, SLOT(setDx(double)));
	connect(ui.dsbDT,    SIGNAL(valueChanged(double)), glw, SLOT(setDt(double)));

	connect(glw, SIGNAL(enableWaveSelectors(bool)), this, SLOT(enableGroupBoxOnes(bool)));
}


void SceneTabWidget::changePlayIcon() {

	m_iconPlay = !m_iconPlay;

	QPixmap pixmap;
	if (m_iconPlay)
		pixmap.load("./icons/play.png");
	else
		pixmap.load("./icons/pause.png");
	ui.buttonPlay->setIcon(QIcon(pixmap));

}

void SceneTabWidget::enableGroupBoxOnes(bool b) {
	ui.groupBoxOnes->setEnabled(b);
}